
R version 2.7.2 (2008-08-25)
Copyright (C) 2008 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

[Previously saved workspace restored]

> library(foreign)
> x <- read.spss("power data.sav")
> x1 <- data.frame(x)
> y <- x1$time_o2
> y <- na.omit(y)
> 
> # See Gilbert's Crash course.handout in the folder in My Docs2
> # Could use boot[i,1] <- mean(bs)
> 
> #
> nb<-1000
> n <- length(y)
> boot<-matrix(NA,nb,6)
> attributes(boot)
$dim
[1] 1000    6

> for (i in 1:nb)
+ {
+ bs<-sample(y,n,replace =T)
+ boot[i,1]<-mean(bs)
+ boot[i,2]<-var(bs)
+ }
> boot[,3]<-sqrt(boot[,2])
> #
> #look at shape of bootstrap distributions
> #
> hist(boot[,1])
> hist(boot[,2])
> hist(boot[,3])
> 
> #
> # Do separately for Males and Females as in RW macro
> # This is R equivalent of the SPSS macro of RW (2004)
> #
> nb <- 1000
> ymale <- matrix(NA,length(y),1)
> 
> for (i in 1:length(y)) {
+ if (x1$sex[i] == 'Male') {
+  ymale[i] <- y[i] }
+ }
> ymale <- na.omit(ymale)
> 
> nm <- length(ymale)
> 
> for (i in 1:nb)
+ {
+ bs<-sample(ymale,nm,replace =T)
+ boot[i,1]<-mean(bs)
+ boot[i,2]<-var(bs)
+ }
> boot[,3]<-sqrt(boot[,2])
> #
> #look at shape of bootstrap distributions
> #
> hist(boot[,1])
> hist(boot[,2])
> hist(boot[,3])
> 
> yfemale <- matrix(NA,length(y),1)
> 
> for (i in 1:length(y)) {
+ if (x1$sex[i] == 'Female') {
+  yfemale[i] <- y[i] }
+ }
> 
> yfemale <- na.omit(yfemale)
> 
> nf <- length(yfemale)
> 
> for (i in 1:nb)
+ {
+ bs<-sample(yfemale,nf,replace =T)
+ boot[i,4]<-mean(bs)
+ boot[i,5]<-var(bs)
+ }
> boot[,6]<-sqrt(boot[,5])
> #
> #look at shape of bootstrap distributions
> #
> hist(boot[,4])
> hist(boot[,5])
> hist(boot[,6])
> 
> poolsd <- matrix(NA,1000,1)
> cohensd <- matrix(NA,1000,1)
> 
> for (i in 1:nb) {
+ poolsd[i] <- ( (nm-1)*boot[i,3]+(nf-1)*boot[i,6] )/(nm+nf-2)
+ 
+ cohensd[i] <- (boot[i,1] - boot[i,4])/poolsd[i]
+ }
> hist(cohensd)
> quantile(cohensd,0.025)
      5% 
1.211717 
> quantile(cohensd,0.975)
     95% 
1.495636 
> 
